package by.ins.life.simpleimpl;

import java.util.ArrayList;
import java.util.List;

import com.mysql.jdbc.Util;

import by.ins.life.IData;
import by.ins.life.evolution.GoalItem;
import by.ins.life.evolution.ITestGoalsProvider;
import by.ins.life.impl.Data;
import by.yativem.commons.utils.math.Utils;
/**
 * 
 * @author Alexey
 *
 * @param <T>
 */
public class TestGoalsProvider<T> implements ITestGoalsProvider<T> {
	
	List<GoalItem<T>> testGoals;
	//private static final int LENGTH = 16;
	private Integer inputDataSize = 16;
	private String providerName;
	private String providerDescription;
	
		
	public Integer getInputDataSize() {
		return inputDataSize;
	}
	
	public void setInputDataSize(Integer inputDataSize) {
		this.inputDataSize = inputDataSize;
	}



	public TestGoalsProvider(int inputDataSize) throws Exception{
		this.setInputDataSize(inputDataSize);
		
		testGoals = new ArrayList<GoalItem<T>>();
		
		for(int i = 0; i < 40; i++){
		/*	GoalItem<T> goalItem = new GoalItem<T>();
			IData<T> inData = new Data<T>();
			goalItem.setInput(inData);
			*/
			GoalItem<T> goalItem = buildTestGoal(i/2, i/3);
			testGoals.add(goalItem);
		}
	}
	
	
	
	private GoalItem<T> buildTestGoal(int num1, int num2 ) throws Exception{
		
		GoalItem<T> goalItem = new GoalItem<T>();
		IData<T> inData = new Data<T>();
		IData<T> disitionData = new Data<T>();
 		
		Byte[] b1 = Utils.convertToBitRepresent(num1, inputDataSize/2);
		
		Byte[] b2 = Utils.convertToBitRepresent(num2, inputDataSize/2);
		
		Byte[] disition = Utils.convertToBitRepresent(num1 + num2, inputDataSize);
		
		Byte[] input  = Utils.concat(b1, b2);
		
		for(Byte b : input){
			Object bb =  b.doubleValue();
			inData.add((T)bb  );
		}
		
		
		for(Byte b : disition){
			Object bb =  b.doubleValue();
			disitionData.add((T)bb  );
		}		
		
		goalItem.setCorrectDicision(disitionData);
		
		goalItem.setInput(inData);
		
		return goalItem;
	}

	@Override
	public List<GoalItem<T>> getTestData(int evolutionIndex) {
		return testGoals;
	}

	@Override
	public List<GoalItem<T>> getNoEvolitionTestData(int evolutionIndex) {
		// TODO Auto-generated method stub
		throw new UnsupportedOperationException("Method is not implemented");
	}
	@Override
	public String getProviderName() {
		return providerName;
	}
	@Override
	public void setProviderName(String providerName) {
		this.providerName = providerName;
	}
	@Override
	public String getProviderDescription() {
		return providerDescription;
	}
	@Override
	public void setProviderDescription(String providerDescription) {
		this.providerDescription = providerDescription;
	}
	
	
	
}
